package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IStatusOfPlanDAO;
import com.AAL.Model.StatusOfPlan;
import com.AAL.Utils.HibernateUtil;

public class StatusOfPlanDAO implements IStatusOfPlanDAO {

	@Override
	public StatusOfPlan getStatusOfPlan(int statusID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StatusOfPlan statusOfPlan = (StatusOfPlan) session.load(
				StatusOfPlan.class, statusID);
		return statusOfPlan;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StatusOfPlan> getAllStatusOfPlans() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StatusOfPlan> lstStatusOfPlans = null;
		try {
			lstStatusOfPlans = (List<StatusOfPlan>) session.createQuery(
					"from StatusOfPlan").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstStatusOfPlans;
	}

}
